package cn.tedu.smartmarketing.business.controller;

import cn.tedu.smartmarketing.base.response.JsonResult;
import cn.tedu.smartmarketing.business.pojo.dto.*;
import cn.tedu.smartmarketing.business.pojo.vo.BusinessVO;
import cn.tedu.smartmarketing.business.pojo.vo.CommentVO;
import cn.tedu.smartmarketing.business.pojo.vo.commodityVo;
import cn.tedu.smartmarketing.business.service.BusinessService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/business")
@Api("商家模块")
public class BusinessController {
    @Autowired
    BusinessService businessService;
    @PostMapping("activity/create")
    public JsonResult createActivity(@RequestBody ActivityCreateParam activityCreateParam){
        log.debug("创建活动：{}",activityCreateParam);
        businessService.createActivity(activityCreateParam);
        return JsonResult.ok();
    }
    @PostMapping("Reg")
    @ApiOperation("商家入驻")
    @ApiOperationSupport(order = 10)
    public JsonResult reg(@RequestBody BusinessRegParam businessRegParam){
        log.debug("商家入驻"+businessRegParam);
        businessService.reg(businessRegParam);
        //前端接收后显示等待审核,24小时内完成。
        return JsonResult.ok();
    }

    @GetMapping("list")
    @ApiOperation("商家列表")
    @ApiOperationSupport(order = 20)
    public JsonResult list(@RequestBody BusinessQuery businessQuery){
        log.debug("商家Id"+businessQuery);
        List<BusinessVO> businessVOS = businessService.list(businessQuery);
        return JsonResult.ok(businessVOS);
    }

    @GetMapping("detail/{businessId}")
    @ApiOperation("商家详细信息")
    @ApiOperationSupport(order = 30)
    public JsonResult detail(@PathVariable Integer businessId){
        log.debug("商家详细信息" +businessId);
        BusinessVO businessVO = businessService.detail(businessId);
        return JsonResult.ok(businessVO);
    }
    @GetMapping("/comment/list/{productId}")
    public JsonResult listComment(@PathVariable Integer productId){
        log.debug("商品评论列表查询{}", productId);
        List<CommentVO> list=businessService.listComment(productId);
        return JsonResult.ok(list);
    }
    @PostMapping("/checks/apply")
    public JsonResult applyChecks(@RequestBody BusinessChecksParam businessChecksParam){
        log.debug("商家申请审核{}", businessChecksParam);
        businessService.applyChecks(businessChecksParam);
        return JsonResult.ok();
    }

    @PostMapping ("/publish")
    public JsonResult publishProduct(Addcommodity addcommodity){
        businessService.publishProduct(addcommodity);
        return JsonResult.ok();
    }
    @PostMapping ("/query")
    public JsonResult queryProduct(commodityQuery commodityQuery){
        List<commodityVo> list = businessService.queryProduct(commodityQuery);
        return JsonResult.ok(list);
    }
}
